/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upc.clases.clase5.dao;

import edu.upc.clases.clase5.entity.Cancha;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author user
 */
public class CanchaDAO extends BaseDAO{
    
    public Integer insertar(Cancha cancha) {
        String insert = "insert into cancha(nombrecancha,caracteristicacancha,codigolocal,codigopromocion) values (?,?,?,?)";
        List list = new ArrayList();
        list.add(cancha.getNombreCancha());
        list.add(cancha.getCaracteristicaCancha());
        list.add(cancha.getCodigoLocal());
        list.add(cancha.getCodigoPromocion());
        
        return this.insert(insert, list);
    }
    
    public void actualizar(Cancha cancha) {
        String update = "update cancha set nombrecancha = ?, caracteristicacancha = ?, codigolocal = ?, codigopromocion = ? where codigocancha = ?";
        List list = new ArrayList();
         list.add(cancha.getNombreCancha());
        list.add(cancha.getCaracteristicaCancha());
        list.add(cancha.getCodigoLocal());
        list.add(cancha.getCodigoPromocion());
        list.add(cancha.getCodigoCancha());
        this.update(update, list);
    }
    
    public void eliminar(Cancha cancha) {
        String delete = "delete from cancha where codigocancha = ?";
        this.delete(delete,cancha.getCodigoCancha());
    }
    
    public List<Cancha> buscar() {
        ResultSet rs = this.select("select * from cancha");
        List<Cancha> listado = new ArrayList<Cancha>();
        try {
            while (rs.next()) {
                Cancha cancha = new Cancha();
                cancha.setCodigoCancha(rs.getInt(1));
                cancha.setNombreCancha(rs.getString(2));
                cancha.setCaracteristicaCancha(rs.getString(3));
                cancha.setCodigoLocal(rs.getInt(4));
                cancha.setCodigoPromocion(rs.getInt(5));
                
                listado.add(cancha);
            }
        } catch (SQLException ex) {
            Logger.getLogger(CanchaDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return listado;
    }  
    
     public List<Cancha> BuscarCanchaFulbito(Cancha pcancha) {
        //ResultSet rs = this.select("select * from canchahorariotarifa where");
         ResultSet rs = this.select("select * from cancha");
        List<Cancha> listado = new ArrayList<Cancha>();
        try {
            while (rs.next()) {
                Cancha cancha = new Cancha();
                
                //cancha.setCodigoHorario(rs.getInt(1));
                //cancha.setCodigoTurno(rs.getInt(2));
                //cancha.setCodigoUbigeo(rs.getString(3));
                //cancha.setDescripcionturno(rs.getString(4));
                //cancha.setTarifa(rs.getDouble(5));
                //cancha.setFlgPromocion(rs.getBoolean(6));
                
                
                cancha.setCodigoCancha(rs.getInt(1));
                cancha.setNombreCancha(rs.getString(2));
                cancha.setCaracteristicaCancha(rs.getString(3));
                cancha.setCodigoLocal(rs.getInt(4));
                cancha.setCodigoPromocion(rs.getInt(5));
                
                listado.add(cancha);
            }
        } catch (SQLException ex) {
            Logger.getLogger(CanchaDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return listado;
    }

   
}
